package com.atguigu.spzx.cloud.order.service.impl;

import com.atguigu.spzx.cloud.model.entity.Order;
import com.atguigu.spzx.cloud.model.entity.User;
import com.atguigu.spzx.cloud.feign.api.UserFeignClient;
import com.atguigu.spzx.cloud.order.mapper.OrderMapper;
import com.atguigu.spzx.cloud.order.service.api.OrderService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.web.client.RestTemplate;

@Service
public class OrderServiceImpl implements OrderService {
	@Autowired
	OrderMapper orderMapper;

	@Autowired
	RestTemplate restTemplate;

	@Autowired
	UserFeignClient userFeignClient;

	@Override
	public Order getOrderByOrderId(Long orderId) {
		Order order = orderMapper.selectOrderByOrderId(orderId);
//		User user = restTemplate.getForObject("http://node:10100/api/user/findUserByUserId/" + order.getUserId(), User.class);
		User user = userFeignClient.findUserByUserId(order.getUserId());
		order.setUser(user);
		return order;
	}
}
